package com.xiaoye.qbproject.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoye.qbproject.domain.BlbcZbRelation;
import com.xiaoye.qbproject.mapper.BlbcZbRelationMapper;
import com.xiaoye.qbproject.service.BlbcZbRelationService;
import com.xiaoye.qbproject.vo.BlbcAndZbRelationVo;
import io.jsonwebtoken.lang.Collections;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【BLBC_ZB_RELATION(兵力编程编组和装备关系)】的数据库操作Service实现
 * @createDate 2025-01-02 11:45:13
 */
@Slf4j
@Service
public class BlbcZbRelationServiceImpl extends ServiceImpl<BlbcZbRelationMapper, BlbcZbRelation>
        implements BlbcZbRelationService {
    /**
     * @param blbcAndZbRelationVo
     * @description: 设置编成编组和装备的关系
     * @author: ChenYao
     * @return: void
     * @ceateDate: 2025-01-02 11:44
     */

    @Override
    public void setBlbcAndZbRelation(BlbcAndZbRelationVo blbcAndZbRelationVo) {
        if (blbcAndZbRelationVo == null) {
            log.info("设置编成编组和装备的关系数据为空");
        }
        String blbcId = blbcAndZbRelationVo.getBlbcId();
        // 删除 兵力编程编组旧的关系信息
        baseMapper.delOldRelationByBlbcId(blbcId);
        List<String> zbIds = blbcAndZbRelationVo.getZbIds();
        // 没有设置,等于清空了
        if (Collections.isEmpty(zbIds)) {
            return;
        }
        // 添加新的关系信息
        zbIds.forEach(zbId -> {
            BlbcZbRelation blbcZbRelation = new BlbcZbRelation();
            blbcZbRelation.setBlbcId(blbcId);
            blbcZbRelation.setZbId(zbId);
            blbcZbRelation.setText(blbcAndZbRelationVo.getText());
            baseMapper.insert(blbcZbRelation);
        });


    }

    /**
     * @param blbcId
     * @description: 获取编成编组和装备的关系
     * @author: ChenYao
     * @return: java.util.List<com.xiaoye.qbproject.domain.BlbcZbRelation>
     * @ceateDate: 2025-01-02 12:54
     */
    @Override
    public List<BlbcZbRelation> getBlbcAndZbRelation(String blbcId) {
        return baseMapper.selectList(Wrappers.<BlbcZbRelation>lambdaQuery().eq(BlbcZbRelation::getBlbcId, blbcId));
    }
}




